#include "FreshBloodCalibration.h"

FreshBloodCalibration::FreshBloodCalibration(QObject *parent)
    : Count(parent),calibrateCount(0),calibrateValid(false),calibrateCompele(false)
{

}

void FreshBloodCalibration::doInit()
{
    //初始化页面参数
    viewDataInit();
    //进入页面直接使能计数功能，使能后响应吸样键。
    //如果计数功能不使能，不响应吸样键。
    setEnable(true);
}

void FreshBloodCalibration::doUnInit()
{

}

void FreshBloodCalibration::calibrateInit()
{
    for(i=0;i<CALIBRATE_COUNT;i++){
        calibBuffer[i].hgb = 0;
        calibBuffer[i].mcv = 0;
        calibBuffer[i].plt = 0;
        calibBuffer[i].rbc = 0;
        calibBuffer[i].wbc = 0;
    }
    calibrateCount = 0;
    calibrateCompele = false;
    calibrateValid = false;
}

void FreshBloodCalibration::viewDataInit()
{
    mFreshBloodViewModel.BloodMode = Count::WHOLD_BLOOD;
    mFreshBloodViewModel.BloodNumber = 1;
    mFreshBloodViewModel.analysisMode = Count::CBCDIFF;
    for(int i=0; i<5; i++){
        for(int j=0; j<CALIBRATE_COUNT; j++){
            mFreshBloodViewModel.param[i][j].check = false;
            mFreshBloodViewModel.param[i][j].wbc = "";
            mFreshBloodViewModel.param[i][j].hgb = "";
            mFreshBloodViewModel.param[i][j].mcv = "";
            mFreshBloodViewModel.param[i][j].rbc = "";
            mFreshBloodViewModel.param[i][j].plt = "";
        }
    }
    mFreshBloodViewModel.target.check = true;//可编辑
    mFreshBloodViewModel.target.wbc = "";
    mFreshBloodViewModel.target.hgb = "";
    mFreshBloodViewModel.target.mcv = "";
    mFreshBloodViewModel.target.plt = "";
    mFreshBloodViewModel.target.rbc = "";
}

void FreshBloodCalibration::setData(QVariant data)
{
    if(data.canConvert<FreshBloodViewModel>()){
        FreshBloodViewModel vModel = data.fromValue<FreshBloodViewModel>(data);

        if(mFreshBloodViewModel.BloodNumber != vModel.BloodNumber)
        {
            calibrateInit();
        }
        mBloodType = vModel.BloodMode;
        mFreshBloodViewModel.BloodNumber = vModel.BloodNumber;
    }
}

bool FreshBloodCalibration::calibrationCompeleted()
{
    return calibrateCompele;
}

bool FreshBloodCalibration::calibrationValid()
{
    return calibrateValid;
}

void FreshBloodCalibration::setCountResult(const CountResultDao &countResult)
{

}


